<template>
	<view class="deta">
		<uv-navbar leftIcon="arrow-leftward" leftIconColor="#FFF" placeholder autoBack bgColor="#161714">
			<template v-slot:center>
				<view class="center_slot">{{data_info.name}}</view>
			</template>
			<!-- <template v-slot:right>
				<view class="right_slot">
					<image src="@/static/images/6.png"></image>
				</view>
			</template> -->
		</uv-navbar>
		<scroll-view scroll-y class="scroll_view">
			<view class="content">
				<image :src="data_info.cover" mode="widthFix" class="cover"></image>
				<view class="info_view">
					<view class="name">【{{data_info.name}}】</view>
					<view class="price">${{data_info.price}}</view>
				</view>
				<view class="link">
					<view class="key">添加您的Steaml链接</view>
					<input type="text" placeholder="请输入steaml链接" class="input" v-model="steaml_url">
				</view>
				<view class="title">商品详情</view>
				<view class="parse_view">
					<uv-parse :content="data_info.content"></uv-parse>
				</view>
			</view>
		</scroll-view>
		<view class="footer">
			<view class="left">
				<text class="unit">$</text>
				<text class="value">{{data_info.price}}</text>
			</view>
			<view class="btn" @click="buy">购买</view>
		</view>
		<uv-popup ref="popup" round="10" bgColor="none" mode="bottom">
			<CodeInput @close="popup.close" @submit="submit" />
		</uv-popup>
	</view>
</template>

<script setup>
	import {
		shopProductInfo,
		shopProductBuy
	} from "@/request/api";
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import {
		ref,
		shallowRef
	} from "vue";
	import CodeInput from "@/components/home/CodeInput.vue"
	import useBase from "@/hooks/useBase.js";
	const {
		router
	} = useBase();

	const data_info = ref({});
	onLoad(async ({
		id
	}) => {
		let {
			info
		} = await shopProductInfo({
			id
		});
		data_info.value = info;
	});

	const popup = shallowRef();
	const buy = () => {
		if (!steaml_url.value) {
			uni.$uv.toast("请输入steaml链接");
			return;
		};
		popup.value.open();
	};

	const steaml_url = ref("");
	const submit = async (value) => {
		let {
			order_id
		} = await shopProductBuy({
			steaml_url: steaml_url.value,
			id: data_info.value.id,
			pay_password: value
		});
		popup.value.close();
		router(`/pages/common/order_result?id=${order_id}`);
		// router('/pages/common/order_result')
	};
</script>

<style scoped lang="scss">
	$footerHeight: 108rpx;

	.deta {
		height: 100vh;
		overflow: hidden;

		.center_slot {
			color: #FFFFFF;
			font-size: 14px;
			font-weight: 800;
		}

		.right_slot {
			image {
				width: 24px;
				height: 24px;
			}
		}

		.scroll_view {
			height: calc(100vh - #{$navBarHeight} - #{$footerHeight});

			.content {
				padding: 20rpx;
				box-sizing: border-box;

				.cover {
					width: 100%;
					border-radius: 20rpx;
				}

				.info_view {
					border-radius: 20rpx;
					margin: 20rpx 0;
					padding: 40rpx 40rpx 48rpx;
					box-sizing: border-box;
					background: #2E2E2E;

					.name {
						color: #FFFFFF;
						font-size: 36rpx;
						font-weight: 800;
					}

					.price {
						color: #DDF247;
						font-size: 40rpx;
						font-family: DINPro;
						padding-top: 40rpx;
						box-sizing: border-box;
					}
				}

				.link {
					border-radius: 20rpx;
					padding: 35rpx 30rpx 20rpx;
					box-sizing: border-box;
					background: #2E2E2E;

					.key {
						color: #FFFFFF;
						font-size: 32rpx;
						font-weight: 800;
					}

					.input {
						height: 78rpx;
						color: #999999;
						font-size: 24rpx;
						font-weight: 400;
						border-radius: 10rpx;
						margin-top: 36rpx;
						padding: 0 30rpx;
						box-sizing: border-box;
						background: rgba(101, 101, 101, 0.2);
					}
				}

				.title {
					height: 100rpx;
					line-height: 90rpx;
					color: #DDF247;
					font-size: 32rpx;
				}

				.parse_view {
					color: #999999;
					font-size: 26rpx;
				}
			}
		}

		.footer {
			height: $footerHeight;
			padding: 0 30rpx;
			box-sizing: border-box;
			background: #111111;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.left {
				.unit {
					color: #DDF247;
					font-size: 40rpx;
				}

				.value {
					color: #DDF247;
					font-size: 60rpx;
					font-family: DINPro;
				}
			}

			.btn {
				width: 200rpx;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				color: #111111;
				font-size: 28rpx;
				font-weight: bold;
				border-radius: 20rpx;
				background: #DDF247;
			}
		}
	}
</style>